﻿Shader "Custom/BillboardClip"
{
    Properties
    {
        _MainTex("MainTex", 2D) = "white" {}
        _Aspect("Aspect", float) = 1
        _Size("Size", float) = 0.5
    }
        SubShader
    {
        Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" "Ignoreprojector" = "True" "DisableBatching" = "True" }

        Pass
    {
        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        Cull Off

        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

        sampler2D _MainTex;
        float4 _MainTex_ST;
        float4 _MainTex_TexelSize;
        float _Size;
        float _Aspect;

        struct a2v
        {
            float4 vertex : POSITION;
            float4 uv : TEXCOORD0;
        };

        struct v2f
        {
            float2 uv : TEXCOORD0;
            float4 pos : SV_POSITION;
        };

        v2f vert(a2v v)
        {
            v2f o;
            float4 center = float4(0, 0, 0, 1);

            o.pos = UnityObjectToClipPos(center);
            o.pos /= o.pos.w;
            o.pos.x += v.vertex.x  * _Size;
            o.pos.y -= v.vertex.y * _Aspect * _Size;
            o.uv = v.uv.xy * _MainTex_ST.xy + _MainTex_ST.zw;
            return o;
        }

        fixed4 frag(v2f i) : SV_Target
        {
            fixed4 color = tex2D(_MainTex, i.uv);
        return color;
        }
            ENDCG
        }
    }
}
